<?php
namespace AuctionCore\Common;


/**
* 常用小功能集合类
*@author爱民
*/
class Util 
{	
	
    //自动格式化为 jsonp 或  json
    public static function auto_jsonp_or_json($req,$data){
        if(isset($req['callback']) && $req['callback']){
            return $req['callback'].'('.json_encode($data,JSON_UNESCAPED_UNICODE).')';
        }else if(isset($req['script_callback']) && $req['script_callback']){
        	return '<script>'.$req['script_callback'].'('.json_encode($data,JSON_UNESCAPED_UNICODE).');'.'</script>';        	
        }
        else
        {
            return json_encode($data,JSON_UNESCAPED_UNICODE);
        }
    }

    /*
    *publish 一条消息到redis
    * @param string $key publish 的key
    * @param mix $val  值
    * @return 返回更新的订阅数
    */
    public static function redis_publish($key,$val){
        $redis = new \Redis();        
        $res = $redis->connect(C('REDIS_HOST'), C('REDIS_PORT'), 1 );
        $res = $redis->publish($key,$val);
        return $res;
    }

}

?>